package de.dqi.pong.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import de.dqi.pong.AILoader;

/**
 * TODO MenuListener - finish class definition
 * <hr>
 * 
 * <hr><dl><dt>
 * Summary: </dt><br><dd>
 *  
 * </dd><br><dt>
 * Author: </dt><br><dd>
 *  Melina
 * </dd></dl>
 */

public class MenuListener
		implements ActionListener {
	
	private static MenuListener	instance;
	
	
	public static MenuListener getInstance() {
		if (instance == null) {
			instance = new MenuListener();
		}
		return instance;
	}
	
	private MenuListener() {
	}
	
	
	@Override
	public void actionPerformed(ActionEvent event) {
		if (((MenuButton) event.getSource()).getNumber() == Frame.GAME) {
			PlayMenu menu = (PlayMenu) ((MenuButton) event.getSource()).getParent();
			System.out.print(AILoader.getLoadedAIs()[menu.getChoiceOne()]);
			System.out.print(" vs ");
			System.out.println(AILoader.getLoadedAIs()[menu.getChoiceTwo()]);
			
			Frame.getInstance().game.loadAIs(menu.getChoiceOne(), menu.getChoiceTwo());
			
			Frame.getInstance().switchPanel(Frame.GAME);
			
		} else {
			Frame.getInstance().switchPanel(((MenuButton) (event.getSource())).getNumber());
			
		}
		
	}
}
